/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Main;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 *
 * @author Sik
 */
public class Toolbox
{

    public static SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
    public static SimpleDateFormat formatterYearOnly = new SimpleDateFormat("yyyy");

    public static Date stringToDate(String sDate)
    {
        try
        {
            return formatter.parse(sDate);
        }
        catch (ParseException ex)
        {
            return null;
        }
    }
    
    public static Date stringToYear(String sDate)
    {
        try
        {
            System.out.println(formatterYearOnly.parse(sDate));
            return formatterYearOnly.parse(sDate);
        }
        catch (ParseException ex)
        {
            return null;
        }
    }
    

    public static Timestamp toDBDateFormat(String sDate) throws ParseException
    {
        return new Timestamp(stringToDate(sDate).getTime());
    }

    public static String dateToString(Date date)
    {
        return formatter.format(date);

    }
}
